<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/13 0013
 * Time: 下午 2:58
 */

namespace App\Http\Classes;


class AudioUpload
{
    private $path = 'EnglishHub';
    private $allowtype = ['mp3', 'wma', 'wav', 'asf', 'aac', 'flac', 'vqf', 'ogg'];
    private $israndname = false;
    private $FileUpload = null;
    private $field = '';
    private $prefix = [
        2 => 'sentence_',
        1 => 'word_'
    ];

    public function __construct($field = '', $type = 1)
    {
        $this->field = $field;
        $this->FileUpload = new FileUpload();
        $this->FileUpload->set('allowtype', $this->allowtype)->set('israndname', $this->israndname)->set('path', $this->path)->set('prefix', $this->prefix[$type]);
    }

    public function setPath($material = 1, $book = 1, $lesson = 1)
    {
        $this->path = $this->path . '/material_' . $material . '/book_' . $book . '/lesson_' . $lesson;
        $this->FileUpload->set('path', $this->path);
    }

    public function upload()
    {
        return $this->FileUpload->upload($this->field);
    }

    public function getErrorMessage()
    {
        return $this->FileUpload->getErrorMessage();
    }

    public function getSavePaths()
    {
        return $this->FileUpload->getSavePaths();
    }
}